Imports System.Data.OracleClient

Public Class frmTableNameAbbreviation

  Public mStrColumnName As String
  Private mBlnIsLoaded As Boolean = False
  Private mObjCommand As OracleCommand
  Private mObjDataReader As OracleDataReader
  Private mArrAbbreviationList As New ArrayList

  Private Sub cmdSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSelect.Click, lstAbbreviationList.DoubleClick
    If lstAbbreviationList.Items.Count > 0 Then
      lstColumnName.Items.Add(lstAbbreviationList.SelectedItem)
      lstColumnName.DisplayMember = "mPrpDisplayMember"
      lstColumnName.ValueMember = "mPrpValueMember"
    End If
  End Sub

  Private Sub frmColumnNameAbbreviation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim lStrQuery As String = ""
    Dim lIntCount As Integer = 0
    Dim lObjClsListBoxProperties As clsMemberProperties

    If mBlnIsLoaded = False Then

      lStrQuery = "Select Distinct TTD_ABRVTD , TTD_DESC from TRDX_TECH_DCTNRY ORDER BY UPPER(TTD_DESC) ASC"

      mObjCommand = New OracleCommand(lStrQuery, con)
      mObjDataReader = mObjCommand.ExecuteReader

      While mObjDataReader.Read
        lObjClsListBoxProperties = New clsMemberProperties
        lObjClsListBoxProperties.mPrpDisplayMember = UCase(mObjDataReader("TTD_DESC"))
        lObjClsListBoxProperties.mPrpValueMember = mObjDataReader("TTD_ABRVTD")
        mArrAbbreviationList.Add(lObjClsListBoxProperties)
      End While

      For lIntCount = 0 To mArrAbbreviationList.Count - 1
        lstAbbreviationList.Items.Add(mArrAbbreviationList.Item(lIntCount))
      Next

      lstAbbreviationList.DisplayMember = "mPrpDisplayMember"
      lstAbbreviationList.ValueMember = "mPrpValueMember"
      mBlnIsLoaded = True

      lstAbbreviationList.Focus()
      lstAbbreviationList.SetSelected(0, True)

    End If
  End Sub

  Private Sub cmdDeSelect_Click(ByVal sender As System.Object _
                              , ByVal e As System.EventArgs) _
                              Handles cmdDeSelect.Click, lstColumnName.DoubleClick
    If lstColumnName.Items.Count > 0 Then
      lstColumnName.Items.Remove(lstColumnName.SelectedItem)
    End If
  End Sub

  Private Sub cmdColumnNameSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdColumnNameSelect.Click
    Dim lIntColumnListBoxItemCount As Integer = 0
    Dim lObjListBoxProperties As clsMemberProperties
    mStrColumnName = ""
    If lstColumnName.Items.Count > 0 Then
      For lIntColumnListBoxItemCount = 0 To lstColumnName.Items.Count - 1
        lObjListBoxProperties = lstColumnName.Items(lIntColumnListBoxItemCount)
        mStrColumnName = mStrColumnName + lObjListBoxProperties.mPrpValueMember + "_"
      Next
      lstColumnName.Items.Clear()
      Me.Close()
    Else

      If MessageBox.Show("No Items to Make Column Name, do you continue?", gCONST_MSG_HEADER, MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
        lstColumnName.Items.Clear()
        Me.Close()
      End If
    End If

  End Sub

  Public Sub New()

    ' This call is required by the Windows Form Designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.

    mStrColumnName = ""

  End Sub

  Private Sub frmColumnNameAbbreviation_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
    If Me.Visible = True Then
      lstAbbreviationList.Focus()
      lstAbbreviationList.SetSelected(0, True)
    End If
  End Sub


  Private Sub cmdUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUp.Click
    Try
      Dim lIntSelectedIndex As Integer

      If lstColumnName.SelectedIndex > 0 Then
        lIntSelectedIndex = lstColumnName.SelectedIndex
        lstColumnName.Items.Insert(lstColumnName.SelectedIndex - 1, lstColumnName.SelectedItem)
        lstColumnName.Items.RemoveAt(lstColumnName.SelectedIndex)
        lstColumnName.Focus()
        lstColumnName.SetSelected(lIntSelectedIndex - 1, True)
      End If

    Finally
    End Try
  End Sub

  Private Sub cmdDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDown.Click
    Try
      Dim lIntSelectedIndex As Integer

      If lstColumnName.SelectedIndex >= 0 And lstColumnName.SelectedIndex <> lstColumnName.Items.Count - 1 Then
        lIntSelectedIndex = lstColumnName.SelectedIndex
        lstColumnName.Items.Insert(lstColumnName.SelectedIndex + 2, lstColumnName.SelectedItem)
        lstColumnName.Items.RemoveAt(lstColumnName.SelectedIndex)
        If (lIntSelectedIndex + 2) >= lstColumnName.Items.Count Then
          lIntSelectedIndex = lstColumnName.Items.Count - 1
        Else
          lIntSelectedIndex = lIntSelectedIndex + 1
        End If

        lstColumnName.Focus()
        lstColumnName.SetSelected(lIntSelectedIndex, True)
      End If

    Finally
    End Try
  End Sub
End Class